import type { ChannelItem, ChannelResData } from "@/types/data"
import axios from "axios"
import { defineStore } from "pinia"
import { computed, ref } from "vue"

export const useCounterStore = defineStore('counter', ()=>{
  const count = ref(0)
  const doubleCount = computed(()=> count.value * 2)
  const add = ()=>count.value++
  const cut = ()=>count.value--

  const channelList = ref<ChannelItem[]>([])
  const getChannelList = async ()=>{
    const res = await axios.get<ChannelResData>(
      "http://geek.itheima.net/v1_0/channels"
    );
    channelList.value = res.data.data.channels;
  }

  return { count, doubleCount, add, cut, channelList, getChannelList };
})